﻿$(document).ready(function () {
    PageLoad();
});

function PageLoad() {
    LoadSodByKey("core.js", null);
    LoadSodByKey("sp.js", null);
    $("#tabs").tabs();
    $("#featured").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 5000, true);
    PageingGridView();
}
/* Paging Functions */
var numberRow = 4;
function PageingGridView() {
    var currentPage = 1;
    var pageCount = Math.ceil(($(".allnews-item").length - 1) / numberRow); //Round up
    if (pageCount < 1) pageCount = 1;
    var viewPage = $("[id$='hdCurrentPage']").val();
    if (viewPage == "LAST") {
        currentPage = pageCount;
    }
    else {
        currentPage = parseInt(viewPage);
        if (currentPage > pageCount)
            currentPage = pageCount;
    }

    PagingChange(currentPage);
    $("#PagingControl").paginate({
        count: pageCount,
        start: currentPage,
        display: 10,
        border: false,
        text_color: '#888',
        background_color: '#EEE',
        text_hover_color: 'black',
        background_hover_color: '#CFCFCF',
        images: false,
        mouse: 'press',
        onChange: function (page) {
            PagingChange(page);
            PageingGridView();
        }
    });
}
function PagingChange(page) {
    SetCurrentPage(page);
    $(".allnews-item").hide();
    //$(".allnews-item div:first").show(); //Header
    var startRow = (page - 1) * numberRow;
    $(".allnews-item:gt(" + startRow + "):lt(" + numberRow + ")").show();
}
function SetCurrentPage(value) {
    $("[id$='hdCurrentPage']").val(value);
}
//End
